<template>
  <div>
    <el-table :data="menuList" border style="width: 100%">
      <el-table-column type="index" width="80" align="center">
      </el-table-column>
      <el-table-column prop="usermessageName" label="用户姓名" align="center">
      </el-table-column>
      <el-table-column prop="usermessageId" label="用户ID" align="center">
      </el-table-column>
      <el-table-column prop="userPhone" label="用户账户" align="center">
      </el-table-column>
      <el-table-column prop="usermessageType" label="用户角色" align="center">
      </el-table-column>
      <el-table-column
        prop="usermessageJobnumber"
        label="用户工号"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="usermessageStatus" label="用户状态" align="center">
        <template slot-scope="scope">
          <el-switch
            @change="
              change(scope.row.usermessageId, scope.row.usermessageStatus)
            "
            v-model="scope.row.usermessageStatus"
            active-text="允许"
            inactive-text="禁止"
            active-value="1"
            inactive-value="0"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column
        prop="usermessageTime"
        label="用户创建时间"
        align="center"
        width="180px"
      >
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button @click="modifyUser(scope.row)" type="text" size="small"
            >修改用户信息</el-button
          >
          <el-button type="text" size="small" @click="modifyPassword(scope.row)"
            >修改密码</el-button
          >
          <el-button
            @click.native.prevent="deleteRow(scope.row.usermessageId)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { removeUser, userState } from "@/network/api/userme/userme";
import mitt from "@/utils/mitt";
export default {
  props: {
    list: {
      type: Array,
      default: () => {},
    },
  },
  data() {
    return {
      usermessageStatus: 0,
      menuList: [],
      userID: 0,
      userInfo: true,
      passwordInfo: true,
      dialogVisible: false,
      info: {
        usermessageId: 0,
        usermessageStatus: "",
      },
    };
  },
  watch: {
    list(newvalue, oldvalue) {
      this.menuList = newvalue;
    },
  },
  methods: {
    // 开关
    async change(id, state) {
      console.log(state, "zhuangt");
      if (state == "1") {
        this.info.usermessageStatus = "0";
      } else {
        this.info.usermessageStatus = "1";
      }
      this.info.usermessageId = id;
      // this.info.usermessageStatus = state;
      console.log(this.info.usermessageId, this.info.usermessageStatus);
      let userinfooState = await userState(
        this.info.usermessageId,
        this.info.usermessageStatus
      );
      console.log(userinfooState, 55555566666666);
      this.$router.go(0);
    },
    // 新建
    deliveryBtn() {
      this.delivery = !this.delivery;
    },

    // 修改用户信息
    modifyUser(data) {
      mitt.emit("isshowU", [this.userInfo]);
      mitt.emit("infolist", data);
    },
    // 修改用户密码
    modifyPassword(data) {
      mitt.emit("isshowP", this.passwordInfo);
      mitt.emit("infopsd", data);
    },
    // 删除用户数据
    async deleteRow(id) {
      this.userID = id;
      this.handleClose(id);
      // this.$router.go(0);
    },
    async remove(id) {
      console.log(id, 22222222222222);
      let removeuser = await removeUser(id);
      this.$router.go(0);
    },
    // 弹框
    async handleClose(done) {
      console.log(done);
      this.$confirm("确认关闭？")
        .then((_) => {
          this.remove(done);
          done();
        })
        .catch((_) => {});
      // let removeuser = await removeUser(done);
    },
  },
};
</script>

<style scoped lang='scss'>
</style>